package services;

import java.util.Map;

import paypalnvp.core.PayPal;
import paypalnvp.core.PayPal.Environment;
import paypalnvp.fields.Currency;
import paypalnvp.fields.Payment;
import paypalnvp.fields.PaymentItem;
import paypalnvp.profile.BaseProfile;
import paypalnvp.profile.Profile;
import paypalnvp.request.SetExpressCheckout;

public class OtherWay {

	private void Paypal(){
		/* set user - these are your credentials from paypal */
		Profile user = new BaseProfile.Builder("dBuyer_1316389818_per@gmail.com","316389650").signature("AfcWX...").build();

		/* create new instance of paypal nvp */
		PayPal pp = new PayPal(user, Environment.SANDBOX);

		/* create items (items from a shopping basket) */
		PaymentItem item1 = new PaymentItem();
		item1.setAmount("12.00");

		PaymentItem item2 = new PaymentItem();
		item2.setAmount("4.30");
		item2.setDescription("Suya");

		PaymentItem[] items = {item1, item2};

		/* create payment (now you can create payment from the items) */
		Payment payment = new Payment(items);
		payment.setCurrency(Currency.GBP);

		/* create set express checkout - the first paypal request */
		SetExpressCheckout setEC = new SetExpressCheckout(payment,
				properties.getProperty("returnUrl"), properties.getProperty("cancelReturn"));

		/* send request and set response */
		pp.setResponse(setEC);

		/* now you have set express checkout containting */
		/* request and response as well */
		Map<String, String> response = setEC.getNVPResponse();
		
		String page3 = 	"<form action=\"https://www.sandbox.paypal.com/cgi-bin/webscr\" method=\"post\">" + 
		"<input name=\"cmd\" value=\"_cart\" type=\"hidden\">" +
		"<input name=\"upload\" value=\"1\" type=\"hidden\">" +
		 "<input type=\"hidden\" name=\"business\" value=\"" + properties.getProperty("business") + "\">" +
		"<input name=\"shopping_url\" value=\"ladirecciondetuweb\" type=\"hidden\">" +
		"<input type=\"hidden\" name=\"currency_code\" value=\"" + properties.getProperty("currency") + "\">" +
		//"<input name=\"return\" value=\"http://mipagina.com/mensaje_de_exito\" type=\"hidden\">" +
		"<input type=\"hidden\" name=\"return\" value=\"" + properties.getProperty("returnUrl") + "\">" +
		"<input name=\"notify_url\" value=\"http://mipagina.com/paypal_ipn.php\" type=\"hidden\">" +
		"<input name=\"rm\" value=\"2\" type=\"hidden\">" +
		//"<input name=\"item_number_1\" value=\"GALLETAS5\" type=\"hidden\">" +
		//"<input type=\"hidden\" name=\"item_number_1\" value=\"" + producto.getDescripcion() + "\">" +
		//"<input name=\"item_name_1\" value=\"Galleta\" type=\"hidden\">" +
		"<input type=\"hidden\" name=\"item_name_1\" value=\"" + producto.getDescripcion() + "\">" +
		//"<input name=\"amount_1\" value=\"5.00\" type=\"hidden\">" +
		 "<input type=\"hidden\" name=\"amount_1\" value=\"" + producto.getPrice() + "\">" +
		"<input name=\"quantity_1\" value=\"1\" type=\"hidden\">" +
		//"<input name=\"item_number_2\" value=\"PIRULETAS3\" type=\"hidden\">" +
		//"<input name=\"item_name_2\" value=\"Piruletas\" type=\"hidden\">" +
		//"<input name=\"amount_2\" value=\"3.00\" type=\"hidden\">" +
		//"<input name=\"quantity_2\" value=\"5\" type=\"hidden\">" +
		"<input value=\"PayPal SandBox\" type=\"submit\">" +
		"</form>";
	}
}
